home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1450.dms / var1450.adf / TrackdiskDevice / Example4.c < prev    next >
C/C++ Source or Header  |  1992-04-27  |  31KB  |  931 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Devices                 Amiga C Club       */
  7. /* Chapter: Trackdisk Device            Tulevagen 22       */
  8. /* File:    Example4.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-04-27                                       */
  11. /* Version: 1.00                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20.  
  21.  
  22. /* This example contains a lot of small and useful */
  23. /* functions that does almost everything you ever  */
  24. /* would like to do with the trackdisk device. The */
  25. /* example has been written so you can easily use  */
  26. /* the functions in your own programs.             */
  27.  
  28.  
  29.  
  30. #include <exec/types.h>        /* Datatypes         */
  31. #include <exec/ports.h>        /* Messages          */
  32. #include <exec/errors.h>       /* IO Error          */
  33. #include <exec/memory.h>       /* Allocating memory */
  34. #include <devices/trackdisk.h> /* Trackdisk Device  */
  35.  
  36.  
  37.  
  38. /* Motor status: */
  39. #define OFF  0
  40. #define ON   1
  41.  
  42. /* Buffer size (512 bytes): */
  43. #define BUFFERSIZE TD_SECTOR
  44.  
  45. /* Disk drives: */
  46. #define DF0 0
  47. #define DF1 1
  48. #define DF2 2
  49. #define DF3 3
  50.  
  51.  
  52.  
  53.  
  54. /* Declare our functions: */
  55.  
  56. void main();
  57.  
  58. void clean_up
  59. (
  60.   BYTE error,
  61.   STRPTR text,
  62.   struct MsgPort *mp,
  63.   struct IOExtTD *req,
  64.   BOOL open,
  65.   BYTE *buf
  66. );
  67.  
  68. BYTE DiskMotor
  69. (
  70.   struct IOExtTD *extreq,
  71.   BYTE status
  72. );
  73.  
  74. void TrackdiskError( BYTE error );
  75.  
  76. ULONG DiskChangeCount( struct IOExtTD *extreq );
  77.  
  78. BYTE ReadDisk
  79. (
  80.   struct IOExtTD *extreq,
  81.   BYTE *buffer,
  82.   ULONG size,
  83.   ULONG counter,
  84.   WORD head,
  85.   WORD cylinder,
  86.   WORD sector
  87. );
  88.  
  89. BYTE WriteDisk
  90. (
  91.   struct IOExtTD *extreq,
  92.   BYTE *buffer,
  93.   ULONG size,
  94.   ULONG counter,
  95.   WORD head,
  96.   WORD cylinder,
  97.   WORD sector
  98. );
  99.  
  100. BYTE FormatDisk
  101. (
  102.   struct IOExtTD *extreq,
  103.   BYTE *buffer,
  104.   ULONG counter,
  105.   WORD head,
  106.   WORD cylinder
  107. );
  108.  
  109. BYTE SeekDisk
  110. (
  111.   struct IOExtTD *extreq,
  112.   ULONG counter,
  113.   WORD head,
  114.   WORD cylinder,
  115.   WORD sector
  116. );
  117.  
  118. BYTE UpdateDisk
  119. (
  120.   struct IOExtTD *extreq,
  121.   ULONG counter
  122. );
  123.  
  124. BYTE ClearDisk
  125. (
  126.   struct IOExtTD *extreq,
  127.   ULONG counter
  128. );
  129.  
  130. ULONG DiskPresent( struct IOExtTD *extreq );
  131.  
  132. ULONG DiskProtected( struct IOExtTD *extreq );
  133.  
  134. ULONG DriveType( struct IOExtTD *extreq );
  135.  
  136. ULONG GetNumTracks( struct IOExtTD *extreq );
  137.  
  138. void RemoveDisk( struct IOExtTD *extreq );
  139.  
  140.  
  141.  
  142. /* This short main program demonstrates some of the functions. */
  143. /* Note that we have put the request block and message port    */
  144. /* structures inside the main program rather than declare them */
  145. /* as global structures. It should then be easier for you to   */
  146. /* use your own request blocks and names.                      */
  147.  
  148. void main()
  149. {
  150.   /* Declare a pointer to our reply port: */
  151.   struct MsgPort *replymp = NULL;
  152.  
  153.   /* Declare a pointer to an IOExtTD structure: */
  154.   struct IOExtTD *our_request = NULL;
  155.  
  156.   /* Have we opened the Trackdisk Device? */
  157.   BOOL device_open = FALSE;
  158.  
  159.   /* Error number: */
  160.   BYTE error;
  161.  
  162.   /* Pointer to our memory buffer: */
  163.   BYTE *buffer = NULL;
  164.  
  165.   /* Drive type: ("DRIVE3_5" or "DRIVE5_25") */
  166.   ULONG drive_type;
  167.  
  168.   /* Number of tracks: */
  169.   ULONG num_tracks;
  170.  
  171.  
  172.  
  173.   /* Get a reply port: */
  174.   replymp = (struct MsgPort *)
  175.     CreatePort( NULL, 0 );
  176.   if( !replymp )
  177.     clean_up
  178.     (
  179.       0,
  180.       "Could not create the reply port!",
  181.       replymp,
  182.       our_request,
  183.       device_open,
  184.       buffer
  185.     );
  186.  
  187.  
  188.   /* Create an IOExtTD structure: */
  189.   our_request = (struct IOExtTD *)
  190.     CreateExtIO( replymp, sizeof( struct IOExtTD ) );
  191.   if( !our_request )
  192.     clean_up
  193.     (
  194.       0,
  195.       "Could not create the IO!",
  196.       replymp,
  197.       our_request,
  198.       device_open,
  199.       buffer
  200.     );
  201.  
  202.  
  203.  
  204.   /* Open the Trackdisk Device: */
  205.   error = OpenDevice( TD_NAME, DF0, our_request, 0 );
  206.   if( error )
  207.     clean_up
  208.     (
  209.       error,
  210.       "Could not open the Trackdisk Device!",
  211.       replymp,
  212.       our_request,
  213.       device_open,
  214.       buffer
  215.     );
  216.   else
  217.     device_open = TRUE;
  218.  
  219.  
  220.  
  221.   /* Demonstrate some of the functions: */
  222.  
  223.   /* Is there a disk in the drive? */
  224.   if( DiskPresent( our_request ) )
  225.     printf( "No disk in drive.\n" );
  226.   else
  227.     printf( "There is a disk in the drive.\n" );
  228.  
  229.  
  230.  
  231.   /* Is the disk write protected? */
  232.   if( DiskProtected( our_request ) )
  233.     printf( "The disk is write protected.\n" );
  234.   else
  235.     printf( "The disk is not write protected.\n" );
  236.  
  237.  
  238.  
  239.   /* What type of disks does it use: (3 1/2" or 5 1/4") */
  240.   drive_type = DriveType( our_request );
  241.   
  242.   if( drive_type == DRIVE3_5 )
  243.     printf( "It is a 3 1/2\" drive.\n" );
  244.   else
  245.     if( drive_type == DRIVE5_25 )
  246.       printf( "It is a 5 1/4\" drive.\n" );
  247.     else
  248.       printf( "It is a very strange drive!\n" );
  249.  
  250.  
  251.  
  252.   /* How many tracks does this drive use: */
  253.   num_tracks = GetNumTracks( our_request );
  254.  
  255.   printf( "Number of tracks: %d (%d / side)\n", num_tracks, num_tracks / 2 );
  256.  
  257.  
  258.  
  259.   /* Clean up and quit: */
  260.   clean_up
  261.   (
  262.     0,
  263.     "The End!",
  264.     replymp,
  265.     our_request,
  266.     device_open,
  267.     buffer
  268.   );
  269. }
  270.  
  271.  
  272.  
  273. /* Close and return everything that has been */
  274. /* opened and allocated before we quit:      */
  275.  
  276. void clean_up
  277. (
  278.   BYTE error,
  279.   STRPTR text,
  280.   struct MsgPort *mp,
  281.   struct IOExtTD *req,
  282.   BOOL open,
  283.   BYTE *buf
  284. )
  285. {
  286.   if( error )
  287.     TrackdiskError( error );
  288.   
  289.   /* Free buffer: */
  290.   if( buf )
  291.     FreeMem( buf, BUFFERSIZE );
  292.  
  293.   /* Close the Trackdisk Device: */ 
  294.   if( open )
  295.     CloseDevice( req );
  296.  
  297.   /* Delete the IOExtTD structure: */
  298.   if( req )
  299.     DeleteExtIO( req, sizeof( struct IOExtTD ) );
  300.  
  301.   /* Remove the replyport: */
  302.   if( mp )
  303.     DeletePort( mp);
  304.  
  305.   /* Print the message: */
  306.   printf( "%s\n", text );
  307.  
  308.   /* Quit: */
  309.   exit( 0 );
  310. }
  311.  
  312.  
  313.  
  314. /* DiskMotor() will turn on/off the diskdrive's motor.  */
  315. /*                                                      */
  316. /* Synopsis:  oldstatus = DiskMotor( new_status );      */
  317. /*                                                      */
  318. /* oldstatus: (BYTE) DiskMotor() returns 1 if the motor */
  319. /*            was already on, else 0 (motor was off).   */
  320. /*                                                      */
  321. /* extreq:    (struct IOExtTD *) Pointer to the request */
  322. /*            block.                                    */
  323. /*                                                      */
  324. /* newstatus: (BYTE) Set this field to 1 (ON) if you    */
  325. /*            want to turn the motor on, else set it to */
  326. /*            0 (OFF) and the motor will be turned off. */
  327. /*            Note! If you turned the motor on when the */
  328. /*            motor was off you must turn it off before */
  329. /*            your program terminates. However, if it   */
  330. /*            was already on you should not turn it     */
  331. /*            off.                                      */
  332.  
  333. BYTE DiskMotor
  334. (
  335.   struct IOExtTD *extreq,
  336.   BYTE status
  337. )
  338. {
  339.   /* Will the user what we will do: */
  340.   printf( "Motor will be turned: %s\n", status ? "On" : "Off" );
  341.  
  342.   /* Set our request: */
  343.   extreq->iotd_Req.io_Command = TD_MOTOR; /* Turn motor on/off. */ 
  344.   extreq->iotd_Req.io_Length = status;    /* 0 = off, 1 = on.   */
  345.  
  346.   /* Do our request, and return when done: */
  347.   DoIO( extreq );
  348.  
  349.   /* DoIO() will return when it has done our request, */
  350.   /* so it will therefore not send us any message to  */
  351.   /* our reply port. If we had used SendIO() instead  */
  352.   /* (returns immediately) we would had to wait for a */
  353.   /* message to arrive at our reply port.             */
  354.  
  355.   /* Check if the motor was on or not before we changed it: */
  356.   printf( "Motor was: %s\n", extreq->iotd_Req.io_Actual ? "On" : "Off" );
  357.  
  358.   /* Return 1 if the motor was already on, 0 if not: */
  359.   return( (BYTE) extreq->iotd_Req.io_Actual );
  360. }
  361.  
  362.  
  363.  
  364. /* TrackdiskError() will give the user some more information */
  365. /* about the error.                                          */
  366. /*                                                           */
  367. /* Synopsis: TrackdiskError( error );                        */
  368. /*                                                           */
  369. /* error:    (BYTE) Give this function the error value, and  */
  370. /*           it will give the user some more information     */
  371. /*           about the error.                                */
  372.  
  373. void TrackdiskError( BYTE error )
  374. {
  375.   printf( "Error code: %d\n", error );
  376.   printf( "Problem: " );
  377.  
  378.   /* The complete list of possible errors: */
  379.   switch( error )
  380.   {
  381.     case TDERR_NotSpecified:
  382.       printf( "Something, we do not know what, failed!\n" );
  383.       break;
  384.  
  385.     case TDERR_NoSecHdr:
  386.       printf( "Could not find a sector!\n" );
  387.       break;
  388.  
  389.     case TDERR_BadSecPreamble:
  390.       printf( "The sector is corrupted!\n" );
  391.       break;
  392.  
  393.     case TDERR_BadSecID:
  394.       printf( "Problems with identifying the sector!\n" );
  395.       break;
  396.  
  397.     case TDERR_BadHdrSum:
  398.       printf( "The header had incorrect checksum!\n" );
  399.       break;
  400.  
  401.     case TDERR_BadSecSum:
  402.       printf( "The sector had incorrect checksum!\n" );
  403.       break;
  404.  
  405.     case TDERR_TooFewSecs:
  406.       printf( "There are too few sectors!\n" );
  407.       break;
  408.  
  409.     case TDERR_BadSecHdr:
  410.       printf( "The sector's header is corrupted!\n" );
  411.       break;
  412.  
  413.     case TDERR_WriteProt:
  414.       printf( "The disk is write protected!\n" );
  415.       break;
  416.  
  417.     case TDERR_DiskChanged:
  418.       printf( "No disk present or disk changed!\n" );
  419.       break;
  420.  
  421.     case TDERR_SeekError:
  422.       printf( "Could not find track 0!\n" );
  423.       break;
  424.  
  425.     case TDERR_NoMem:
  426.       printf( "Not enough memory!\n" );
  427.       break;
  428.  
  429.     case TDERR_BadUnitNum:
  430.       printf( "Requested diskdrive does not exist!\n" );
  431.       break;
  432.  
  433.     case TDERR_BadDriveType:
  434.       printf( "The Trackdisk Device can not handle that diskdrive!\n" );
  435.       break;
  436.  
  437.     case TDERR_DriveInUse:
  438.       printf( "The requested diskdrive is already used by someone else!\n" );
  439.       break;
  440.  
  441.     case TDERR_PostReset:
  442.       printf( "Oh no! The user hit the reset buttons, we are going down!\n" );
  443.       break;
  444.  
  445.  
  446.     /* The standard device errors: */
  447.  
  448.     case IOERR_OPENFAIL:
  449.       printf( "Could not open the device!\n" );
  450.       break;
  451.  
  452.     case IOERR_ABORTED:
  453.       printf( "The request was aborted!\n" );
  454.       break;
  455.       
  456.     case IOERR_NOCMD:
  457.       printf( "Not a valid command! Not supported by the trackdisk device!\n" );
  458.       break;
  459.       
  460.     case IOERR_BADLENGTH:
  461.       printf( "Bad length or value!\n" );
  462.       break;
  463.  
  464.     default:
  465.       /* Unknown error value: */
  466.       printf( "What? Unknown error code!\n" );
  467.   }
  468. }
  469.  
  470.  
  471.  
  472. /* DiskChangeCount() returns the current disk's "count value". */
  473. /* If the value has changet we know that the disk has been     */
  474. /* removed and/or changed.                                     */
  475. /*                                                             */
  476. /* Synopsis: count = DiskChangeCount( extreq );                */
  477. /*                                                             */
  478. /* count:    (ULONG) The disk's "change count value".          */
  479. /*                                                             */
  480. /* extreq:   (struct IOExtTD *) Pointer to the request block.  */
  481.  
  482. ULONG DiskChangeCount( struct IOExtTD *extreq )
  483. {
  484.   /* Get the disk's change count value: */
  485.   extreq->iotd_Req.io_Command = TD_CHANGENUM;
  486.  
  487.   /* Do our request, and return when completed: */
  488.   DoIO( extreq );
  489.   
  490.   /* Return the answer: */
  491.   return( (ULONG) extreq->iotd_Req.io_Actual );
  492. }
  493.  
  494.  
  495.  
  496. /* ReadDisk() will start to read a specified number of bytes of data,     */
  497. /* and store it in the buffer. Before you call this function you should   */
  498. /* have got the disk's current count value by using our DiskChangeCount() */
  499. /* function. If you do not want to check if the disk has been changed,    */
  500. /* set the counter field to 0xFFFF.                                       */
  501. /*                                                                        */
  502. /* Synopsis: er = ReadDisk( req, buf, size, count, head, cyl, sec );      */
  503. /*                                                                        */
  504. /* er:       (BYTE) ReadDisk() returns 0 if everything was OK, else an    */
  505. /*           error number is returned. Use our function TrackdiskError()  */
  506. /*           to find out what went wrong.                                 */
  507. /*                                                                        */
  508. /* req:      (struct IOExtTD *) Pointer to the request block.             */
  509. /*                                                                        */
  510. /* buf:      (BYTE *) Pointer to a buffer in which all data will be       */
  511. /*           stored. Make sure that this buffer is at least as big as     */
  512. /*           the specified number of bytes that should be read (size).    */
  513. /*                                                                        */
  514. /* size:     (ULONG) The number of bytes that should be read.             */ 
  515. /*                                                                        */
  516. /* count:    (ULONG) This disk current counter value. Use our function    */
  517. /*           DiskChangeCount() to get the current count value.            */
  518. /*                                                                        */
  519. /* head:     (WORD) Which head should be used. [0-1]                      */
  520. /*                                                                        */
  521. /* cyl:      (WORD) Start at this cylinder. [0-79]                        */
  522. /*                                                                        */
  523. /* sec:      (WORD) Start at this sector. [0-10]                          */
  524.  
  525. BYTE ReadDisk
  526. (
  527.   struct IOExtTD *extreq,
  528.   BYTE *buffer,
  529.   ULONG size,
  530.   ULONG counter,
  531.   WORD head,
  532.   WORD cylinder,
  533.   WORD sector
  534. )
  535. {
  536.   /* We want to read: */
  537.   extreq->iotd_Req.io_Command = ETD_READ;
  538.  
  539.   /* Pointer to the buffer: */
  540.   extreq->iotd_Req.io_Data = (APTR) buffer;
  541.  
  542.   /* Number of bytes that should be read: */
  543.   extreq->iotd_Req.io_Length = size;
  544.  
  545.   /* Set current disk count value: (If the value has changed */
  546.   /* this request will be cancelled.)                        */
  547.   extreq->iotd_Count = counter;
  548.  
  549.   /* Start to read at position: (The diskdrive has 2 heads, 80 */
  550.   /* cylinders which each consists of 11 (NUMSECS) sectors,    */
  551.   /* with 512 (TD_SECTOR) usable bytes of data each.)          */ 
  552.   extreq->iotd_Req.io_Offset = (LONG)
  553.    TD_SECTOR*( NUMSECS * 2 * cylinder + NUMSECS * head + sector );
  554.  
  555.   /* Do our request, and return when completed: */
  556.   DoIO( extreq );
  557.  
  558.   /* Return error value: (0: OK, else ERROR) */
  559.   return( (BYTE) extreq->iotd_Req.io_Error );
  560. }
  561.  
  562.  
  563.  
  564. /* WriteDisk() will start to write a specified number of bytes of data.   */
  565. /* Before you call this function you should have got the disk's current   */
  566. /* count value by using our DiskChangeCount() function. If you do not     */
  567. /* want to check if the disk has been changed, set the counter field to   */
  568. /* 0xFFFF.                                                                */
  569. /*                                                                        */
  570. /* Synopsis: er = WriteDisk( req, buf, size, count, head, cyl, sec );     */
  571. /*                                                                        */
  572. /* er:       (BYTE) WriteDisk() returns 0 if everything was OK, else an   */
  573. /*           error number is returned. Use our function TrackdiskError()  */
  574. /*           to find out what went wrong.                                 */
  575. /*                                                                        */
  576. /* req:      (struct IOExtTD *) Pointer to the request block.             */
  577. /*                                                                        */
  578. /* buf:      (BYTE *) Pointer to a buffer from which all data will be     */
  579. /*           fetched. Make sure that this buffer is at least as big as    */
  580. /*           the specified number of bytes that should be written (size). */
  581. /*                                                                        */
  582. /* size:     (ULONG) The number of bytes that should be written.          */ 
  583. /*                                                                        */
  584. /* count:    (ULONG) This disk current counter value. Use our function    */
  585. /*           DiskChangeCount() to get the current count value.            */
  586. /*                                                                        */
  587. /* head:     (WORD) Which head should be used. [0-1]                      */
  588. /*                                                                        */
  589. /* cyl:      (WORD) Start at this cylinder. [0-79]                        */
  590. /*                                                                        */
  591. /* sec:      (WORD) Start at this sector. [0-10]                          */
  592.  
  593. BYTE WriteDisk
  594. (
  595.   struct IOExtTD *extreq,
  596.   BYTE *buffer,
  597.   ULONG size,
  598.   ULONG counter,
  599.   WORD head,
  600.   WORD cylinder,
  601.   WORD sector
  602. )
  603. {
  604.   /* We want to write: */
  605.   extreq->iotd_Req.io_Command = ETD_WRITE;
  606.  
  607.   /* Pointer to the buffer: */
  608.   extreq->iotd_Req.io_Data = (APTR) buffer;
  609.  
  610.   /* Number of bytes that should be written: */
  611.   extreq->iotd_Req.io_Length = size;
  612.  
  613.   /* Set current disk count value: (If the value has changed */
  614.   /* this request will be cancelled.)                        */
  615.   extreq->iotd_Count = counter;
  616.  
  617.   /* Start to write at position: (The diskdrive has 2 heads,   */
  618.   /* 80 cylinders which each consists of 11 (NUMSECS) sectors, */
  619.   /* with 512 (TD_SECTOR) usable bytes of data each.)          */ 
  620.   extreq->iotd_Req.io_Offset = (LONG)
  621.    TD_SECTOR*( NUMSECS * 2 * cylinder + NUMSECS * head + sector );
  622.  
  623.   /* Do our request, and return when completed: */
  624.   DoIO( extreq );
  625.  
  626.   /* Return error value: (0: OK, else ERROR) */
  627.   return( (BYTE) extreq->iotd_Req.io_Error );
  628. }
  629.  
  630.  
  631.  
  632. /* FormatDisk() will format a specified cylinder.                         */
  633. /*                                                                        */
  634. /* Synopsis: error = FormatDisk( req, buffer, count, head, cylinder );    */
  635. /*                                                                        */
  636. /* error:    (BYTE) FormatDisk() returns 0 if everything was OK, else an  */
  637. /*           error number is returned. Use our function TrackdiskError()  */
  638. /*           to find out what went wrong.                                 */
  639. /*                                                                        */
  640. /* req:      (struct IOExtTD *) Pointer to the request block.             */
  641. /*                                                                        */
  642. /* buffer:   (BYTE *) Pointer to a buffer which contains the data that    */
  643. /*           will be stored on the reformatted cylinder. Make sure that   */
  644. /*           this buffer is at least one cylinder of bytes large.         */
  645. /*           (NUMSECS * TD_SECTOR)                                        */
  646. /*                                                                        */
  647. /* count:    (ULONG) This disk current counter value. Use our function    */
  648. /*           DiskChangeCount() to get the current count value.            */
  649. /*                                                                        */
  650. /* head:     (WORD) Which head should be used. [0-1]                      */
  651. /*                                                                        */
  652. /* cylinder: (WORD) The cylinder which sould be formatted. [0-79]         */
  653.  
  654. BYTE FormatDisk
  655. (
  656.   struct IOExtTD *extreq,
  657.   BYTE *buffer,
  658.   ULONG counter,
  659.   WORD head,
  660.   WORD cylinder
  661. )
  662. {
  663.   /* We want to format: */
  664.   extreq->iotd_Req.io_Command = ETD_FORMAT;
  665.  
  666.   /* Pointer to the buffer: */
  667.   extreq->iotd_Req.io_Data = (APTR) buffer;
  668.  
  669.   /* Format one cylinder: */
  670.   extreq->iotd_Req.io_Length = NUMSECS * TD_SECTOR;
  671.  
  672.   /* Set current disk count value: (If the value has changed */
  673.   /* this request will be cancelled.)                        */
  674.   extreq->iotd_Count = counter;
  675.  
  676.   /* Start at position: */
  677.   extreq->iotd_Req.io_Offset = (LONG)
  678.    TD_SECTOR*( NUMSECS * 2 * cylinder + NUMSECS * head );
  679.  
  680.   /* Do our request, and return when completed: */
  681.   DoIO( extreq );
  682.  
  683.   /* Return error value: (0: OK, else ERROR) */
  684.   return( (BYTE) extreq->iotd_Req.io_Error );
  685. }
  686.  
  687.  
  688.  
  689. /* SeekDisk() will move the head to a specified position. Not extremely   */
  690. /* useful, but maybe someone needs to do it.                              */
  691. /*                                                                        */
  692. /* Synopsis: er = SeekDisk( req, count, head, cyl, sec );                 */
  693. /*                                                                        */
  694. /* er:       (BYTE) returns 0 if everything was OK, else an error number  */
  695. /*           is returned. Use our function TrackdiskError() to find out   */
  696. /*           what went wrong.                                             */
  697. /*                                                                        */
  698. /* req:      (struct IOExtTD *) Pointer to the request block.             */
  699. /*                                                                        */
  700. /* count:    (ULONG) This disk current counter value. Use our function    */
  701. /*           DiskChangeCount() to get the current count value.            */
  702. /*                                                                        */
  703. /* head:     (WORD) Which head. [0-1]                                     */
  704. /*                                                                        */
  705. /* cyl:      (WORD) Move to cylinder. [0-79]                              */
  706. /*                                                                        */
  707. /* sec:      (WORD) Move to sector. [0-10]                                */
  708.  
  709. BYTE SeekDisk
  710. (
  711.   struct IOExtTD *extreq,
  712.   ULONG counter,
  713.   WORD head,
  714.   WORD cylinder,
  715.   WORD sector
  716. )
  717. {
  718.   /* We want to position the head: */
  719.   extreq->iotd_Req.io_Command = ETD_SEEK;
  720.  
  721.   /* Set current disk count value: (If the value has changed */
  722.   /* this request will be cancelled.)                        */
  723.   extreq->iotd_Count = counter;
  724.  
  725.   /* Move to position: */
  726.   extreq->iotd_Req.io_Offset = (LONG)
  727.    TD_SECTOR*( NUMSECS * 2 * cylinder + NUMSECS * head + sector );
  728.  
  729.   /* Do our request, and return when completed: */
  730.   DoIO( extreq );
  731.  
  732.   /* Return error value: (0: OK, else ERROR) */
  733.   return( (BYTE) extreq->iotd_Req.io_Error );
  734. }
  735.  
  736.  
  737.  
  738. /* UpdateDisk() will update the trackdisk device's internal buffer. If  */
  739. /* there is anything left in the buffer it will be copied out onto the  */
  740. /* disk. You shuld always update the disk after you have finished       */
  741. /* writing and just before you stop the motor.                          */
  742. /*                                                                      */
  743. /* Synopsis: error = UpdateDisk( req, count );                          */
  744. /*                                                                      */
  745. /* error:    (BYTE) returns 0 if everything was OK, else an error       */
  746. /*           number is returned.                                        */
  747. /*                                                                      */
  748. /* req:      (struct IOExtTD *) Pointer to the request block.           */
  749. /*                                                                      */
  750. /* count:    (ULONG) This disk current counter value. Use our function  */
  751. /*           DiskChangeCount() to get the current count value.          */
  752.  
  753. BYTE UpdateDisk
  754. (
  755.   struct IOExtTD *extreq,
  756.   ULONG counter
  757. )
  758. {
  759.   /* We want to update the internal buffer: */
  760.   extreq->iotd_Req.io_Command = ETD_UPDATE;
  761.  
  762.   /* Set current disk count value: (If the value has changed */
  763.   /* this request will be cancelled.)                        */
  764.   extreq->iotd_Count = counter;
  765.  
  766.   /* Do our request, and return when completed: */
  767.   DoIO( extreq );
  768.  
  769.   /* Return error value: (0: OK, else ERROR) */
  770.   return( (BYTE) extreq->iotd_Req.io_Error );
  771. }
  772.  
  773.  
  774.  
  775. /* ClearDisk() will clear the trackdisk device's internal buffer. It is */
  776. /* always good to clear the internal buffer when you realize that the   */
  777. /* user has changed disks. Old data from the first disk will then not   */
  778. /* accidentally be stored on the new disk.                              */
  779. /*                                                                      */
  780. /* Synopsis: error = ClearDisk( req, count );                           */
  781. /*                                                                      */
  782. /* error:    (BYTE) returns 0 if everything was OK, else an error       */
  783. /*           number is returned.                                        */
  784. /*                                                                      */
  785. /* req:      (struct IOExtTD *) Pointer to the request block.           */
  786. /*                                                                      */
  787. /* count:    (ULONG) This disk current counter value. Use our function  */
  788. /*           DiskChangeCount() to get the current count value.          */
  789.  
  790. BYTE ClearDisk
  791. (
  792.   struct IOExtTD *extreq,
  793.   ULONG counter
  794. )
  795. {
  796.   /* We want to clear the internal buffer: */
  797.   extreq->iotd_Req.io_Command = ETD_CLEAR;
  798.  
  799.   /* Set current disk count value: (If the value has changed */
  800.   /* this request will be cancelled.)                        */
  801.   extreq->iotd_Count = counter;
  802.  
  803.   /* Do our request, and return when completed: */
  804.   DoIO( extreq );
  805.  
  806.   /* Return error value: (0: OK, else ERROR) */
  807.   return( (BYTE) extreq->iotd_Req.io_Error );
  808. }
  809.  
  810.  
  811.  
  812. /* DiskPresent() will return 0 if there is a disk in the drive, */
  813. /* else a non zero value is returned.                           */
  814. /*                                                              */
  815. /* Synopsis: disk = DiskPresent( req );                         */
  816. /*                                                              */
  817. /* disk:     (ULONG) returns 0 if there is a disk in the drive, */
  818. /*           else a non zero value is returned.                 */
  819. /*                                                              */
  820. /* req:      (struct IOExtTD *) Pointer to the request block.   */
  821.  
  822. ULONG DiskPresent( struct IOExtTD *extreq )
  823. {
  824.   extreq->iotd_Req.io_Command = TD_CHANGESTATE;
  825.  
  826.   /* Do our request, and return when completed: */
  827.   DoIO( extreq );
  828.  
  829.   /* Return 0 if there is a disk in the drive, else a non zero value: */
  830.   return( extreq->iotd_Req.io_Actual );
  831. }
  832.  
  833.  
  834.  
  835. /* DiskProtected() will return 0 if the disk is not protected,  */
  836. /* else (disk is write protected) a non zero value is returned. */
  837. /*                                                              */
  838. /* Synopsis:  protected = DiskProtected( req );                 */
  839. /*                                                              */
  840. /* protected: (ULONG) returns 0 if the disk is not protected,   */
  841. /*            else (disk is write protected) a non zero value   */
  842. /*            is returned.                                      */
  843. /*                                                              */
  844. /* req:      (struct IOExtTD *) Pointer to the request block.   */
  845.  
  846. ULONG DiskProtected( struct IOExtTD *extreq )
  847. {
  848.   /* Check is the disk is protected or not: */
  849.   extreq->iotd_Req.io_Command = TD_PROTSTATUS;
  850.  
  851.   /* Do our request, and return when completed: */
  852.   DoIO( extreq );
  853.  
  854.   /* Return 0 if the disk is not protected, else a non zero value: */
  855.   return( extreq->iotd_Req.io_Actual );
  856. }
  857.  
  858.  
  859.  
  860. /* DriveType() will return "DRIVE3_5" if it is a normal 3 1/2" disk  */
  861. /* in the drive, or it it returns "DRIVE5_25" if it is a 5 1/4 disk. */
  862. /*                                                                   */
  863. /* Synopsis:   drive_type = DriveType( req );                        */
  864. /*                                                                   */
  865. /* drive_type: (ULONG) returns "DRIVE3_5" if it is a normal 3 1/2"   */
  866. /*             disk drive, else it returns "DRIVE5_25" if it is a    */
  867. /*             5 1/4 disk drive.                                     */
  868. /*                                                                   */
  869. /* req:        (struct IOExtTD *) Pointer to the request block.      */
  870.  
  871. ULONG DriveType( struct IOExtTD *extreq )
  872. {
  873.   /* Check drive type: */
  874.   extreq->iotd_Req.io_Command = TD_GETDRIVETYPE;
  875.  
  876.   /* Do our request, and return when completed: */
  877.   DoIO( extreq );
  878.  
  879.   /* Return drive type: (DRIVE3_5 or DRIVE5_25) */
  880.   return( extreq->iotd_Req.io_Actual );
  881. }
  882.  
  883.  
  884.  
  885. /* GetNumTracks() will return the number of tracks the drive is      */
  886. /* using. Remember that if you test it on a double sided drive the   */
  887. /* function will count the tracks on both sides. A normal 3 1/2"     */
  888. /* drive is using 160 tracks (80 tracks / head - side ).             */ 
  889. /*                                                                   */
  890. /* Synopsis:   num_tracks = GetNumTracks( req );                     */
  891. /*                                                                   */
  892. /* num_tracks: (ULONG) returns the number of tracks the drive is     */
  893. /*             using.                                                */
  894. /*                                                                   */
  895. /* req:        (struct IOExtTD *) Pointer to the request block.      */
  896.  
  897. ULONG GetNumTracks( struct IOExtTD *extreq )
  898. {
  899.   /* Get the number of tracks this drive is using: */
  900.   extreq->iotd_Req.io_Command = TD_GETNUMTRACKS;
  901.  
  902.   /* Do our request, and return when completed: */
  903.   DoIO( extreq );
  904.  
  905.   /* Return the number of tracks: */
  906.   return( extreq->iotd_Req.io_Actual );
  907. }
  908.  
  909.  
  910.  
  911. /* RemoveDisk() makes the system beleive that the user has removed    */
  912. /* and/or changed the disks. It will cause the disk drive to increase */
  913. /* its own internal count value.                                      */
  914. /*                                                                    */
  915. /* Synopsis:   RemoveDisk( req );                                     */
  916. /*                                                                    */
  917. /* req:        (struct IOExtTD *) Pointer to the request block.       */
  918.  
  919. void RemoveDisk( struct IOExtTD *extreq )
  920. {
  921.   /* Let the system think that the user */
  922.   /* has removed and/or changed disks:  */
  923.   extreq->iotd_Req.io_Command = TD_REMOVE;
  924.  
  925.   /* Do our request, and return when completed: */
  926.   DoIO( extreq );
  927. }
  928.  
  929.  
  930.  
  931.